package com.bzkj.basicinfo.utils;

import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * @Date 2024/12/19 14:47:21
 * @description
 */
@Component
public class HttpClientUtils
{
    @Value("${ncc.sourceSystem}")
    private  String sourceSystem;

    @Value("${ncc.targetSystem}")
    private  String targetSystem;

    @Value("${ncc.serviceName}")
    private  String serviceName;

    @Value("${ncc.contentType}")
    private  String contentType;

    @Value("${ncc.basicInfoUrl}")
    private  String basicInfoUrl;

    public HttpResponse methodExecute(String startTimeStr, String endTimeStr, Integer i, Integer platformCode)
    {
        HashMap<String, Object> hashMap = new HashMap<>();

        // 添加post请求参数
        hashMap.put("startTime", startTimeStr);
        hashMap.put("endTime", endTimeStr);
        hashMap.put("nccBaseDataEnum", i);
        hashMap.put("platformCode", platformCode);
        String jsonString = JSONUtil.toJsonStr(hashMap);

        // 添加请求头并执行请求
        return HttpUtil.createPost(basicInfoUrl)
                .header("sourceSystem", sourceSystem)
                .header("targetSystem", targetSystem)
                .header("serviceName", serviceName)
                .header("contentType", contentType)
                .body(jsonString, "application/json")
                .execute();
    }

    public HttpResponse methodExecute(String startTimeStr, String endTimeStr, String nccBaseDataEnum, String platformCode)
    {
        String url = "http://192.168.132.202:8010/WMS/GetBaseData";
        HashMap<String, Object> hashMap = new HashMap<>();

        // 添加post请求参数
        hashMap.put("startTime", startTimeStr);
        hashMap.put("endTime", endTimeStr);
        hashMap.put("nccBaseDataEnum", nccBaseDataEnum);
        hashMap.put("platformCode", platformCode);
        String jsonString = JSONUtil.toJsonStr(hashMap);
        System.out.println(basicInfoUrl);
        // 添加请求头并执行请求
        HttpResponse response = HttpUtil.createPost(basicInfoUrl)
                .header("sourceSystem", sourceSystem)
                .header("targetSystem", targetSystem)
                .header("serviceName", serviceName)
                .header("contentType", contentType)
                .body(jsonString, "application/json")
                .execute();
        return response;
    }
}
